package com.protocolterminal.AFN.entity;

import java.util.List;

import com.protocolterminal.function.FrameFunction;

public class AFN10F1 implements Interface_Data {

	@Override
	public String frametolist(String frame) throws Exception {

		FrameFunction frameFunction = new FrameFunction();

		int i = Integer.valueOf(frameFunction.Reverse(frame.substring(2, 6)), 16);

		return frame.substring(6, 6 + i * 2);
	}

	@Override
	public String listtoframe(List<String> datalist) throws Exception {
		if (datalist.size() != 10) {
			return null;
		}

		String data = "";

		data += Integer.toHexString(Integer.valueOf(datalist.get(0)) | 0x100).substring(1);

		int baud = Integer.valueOf(datalist.get(1)) << 5;
		int stop = Integer.valueOf(datalist.get(2)) << 4;
		int ischeck = Integer.valueOf(datalist.get(3)) << 3;
		int check = Integer.valueOf(datalist.get(4)) << 2;
		int num = Integer.valueOf(datalist.get(5)) - 5;

		data += Integer.toHexString(baud | stop | ischeck | check | num | 0x100).substring(1);

		int time = Integer.valueOf(datalist.get(6));
		int time1 = Integer.valueOf(datalist.get(7)) << 7;
		data += Integer.toHexString(time | time1 | 0x100).substring(1);

		data += Integer.toHexString(Integer.valueOf(datalist.get(8)) | 0x100).substring(1);

		int len = datalist.get(9).length() / 2;
		FrameFunction frameFunction = new FrameFunction();
		data += frameFunction.Reverse(Integer.toHexString(len | 0x10000).substring(1));
		data += datalist.get(9);

		return data;
	}

}
